package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.pojo.Result;
import com.qf.pojo.Setmeal;
import com.qf.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @GetMapping("/{page}/{size}")
    public Result findByPage(@PathVariable int page, @PathVariable int size){

        IPage<Setmeal> ipage = new Page<>(page,size);
        setmealService.page(ipage);

        return Result.success(ipage);
    }

    @PostMapping
    public Result addSetmeal(String checkgroupIds,@RequestBody Setmeal setmeal){
        String[] split = null;
        if (checkgroupIds!=null && checkgroupIds.length()!=0){
             split = checkgroupIds.split(",");
        }

        setmealService.saveSetmeal(setmeal,split);

        return Result.success(null);
    }
}
